home *** CD-ROM | disk | FTP | other *** search
- Path: keats.ugrad.cs.ubc.ca!not-for-mail
- From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
- Newsgroups: comp.lang.c,comp.lang.c++
- Subject: Re: GPF in BC++ 4.5
- Date: 16 Feb 1996 20:40:28 -0800
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Message-ID: <4g3m7sINNsbb@keats.ugrad.cs.ubc.ca>
- References: <4g2oqf$sjc@nntp5.u.washington.edu>
- NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
-
- In article <4g2oqf$sjc@nntp5.u.washington.edu>,
- Todd Stedl <trstedl@u.washington.edu> wrote:
- >I'm having problems with a General Protection Exception that I
- >continually get from a program I run in Borland C++ 4.5. The reason I'm
- >cross posting to the C group is b/c it's a standard C program. I've
- >looked at Borland's Web site but found no help there.
- >
- >Here's the basics of the program:
- >I use a lot of arrays and need to write to 2 separate data files, so I
- >allocate the memory accordingly. I allocate the the file names as
- >pointers to char since their names may change depending upon certain
- >parameters in the program.
- > char *over_name, *data_name;
- >
- >In the main program I reserve memory for the names.
- > over_name = (char*)malloc(20*sizeof(char));
- > data_name = ...
-
- You don't have to. They could well be declared as:
-
- char over_name[20], data_name[<whatever>];
-
- This is another way to reserve memory without requiring a call to the
- allocator. If you are never going to change the pointer, don't bother with
- malloc.
-
- >
- >And the very last thing I do in main is free the memory.
- > free(over_name);
- > etc.
- >
- >At that point I'm also freeing all the arrays I've used, too.
- >
- >Now, whenever the program executes the free(over_name) line, I get the
- >following runtime error:
-
- IT's hard to know what is going on. It could be a bug caused by you that you
- don't see (e.g. memory corruption). Try to do some "self help". Did you already
- try print the value of the over_name pointer right after you malloc() it and
- before you free() it? Did you try using a debugger? Did you try porting your
- program to another environment to see how it behaves there?
- --
-
-